
function Encrypt(word){
  var key = CryptoJS.enc.Utf8.parse("abcdefgabcdefghi"); 

  var srcs = CryptoJS.enc.Utf8.parse(word);
  var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
  return encrypted.toString();
}

function Decrypt(word){
  var key = CryptoJS.enc.Utf8.parse("abcdefgabcdefghi"); 

  var decrypt = CryptoJS.AES.decrypt(word, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
  return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}


function dologin(){

  $.ajax({
    type:"get",    
    contentType: "application/json",
    headers:{},
    url:AllUrl+'public/rsakey',
    success: function(data){
      var username=$("#username").val();
      var password =$("#password").val();

      var verifyCode =$("#verifyCode").val();

      var encrypt = new JSEncrypt();
      encrypt.setPublicKey(data.dataResultObj.RsaKey);
//    console.log("json.thePubKey:"+data.dataResultObj.RsaKey);
      username=username;
      password=password;
      username=encrypt.encrypt(username);
      password=encrypt.encrypt(password);

      // console.log(username);
      // console.log(password);

      $.ajax({
        type:"post",
        contentType: "application/json",
        headers:{'AdminToken':localStorage.LoginToken},
        url: AllUrl+'system/admin/login',    
        data:"{'username':'"+username+"','password':'"+password+"','IdentifyCode':'"+verifyCode+"'}",
        success: function(data){
        	if(data.htmlState.status==200){
        		console.log(data);
	          localStorage.AdminToken=data.dataResultObj.adminToken
	          
	          
	          window.location.href = 'index.html'   
        	}else if(data.htmlState.status==205){
        		ajaxcode();
        	}else{
        		layer.msg(data.htmlState.message);
//      		ajaxcode();
        	}
          
        } 
      });


    } 
  });


}

ajaxcode();
$("#verifyimg").click(function () {
    ajaxcode()
})


function ajaxcode(){
//	获取验证码
  $.ajax({
    type:"get",
    contentType: "application/json", 
//  headers:{'AdminToken':localStorage.AdminToken},
    url: AllUrl+'public/system/getverificode',    
    data:new Date().getTime(),
    success: function(data){
//    console.log(localStorage.AdminToken)
      localStorage.LoginToken=data.dataResultObj.LoginToken
      $("#verifyimg").attr("src", "data:image/png;base64,"+data.dataResultObj.CodeImg);



   } 
  });
}

